﻿namespace Sustainalytics.Portfolios.Servive.Tests
{
    using System.Net;
    using System.Net.Http;
    using System.Threading.Tasks;

    using Microsoft.Owin.Testing;

    using Xunit;

    public partial class PortfolioServiceTests
    {
        public class AuthorizationTests : PortfolioServiceTests
        {
            [Fact]
            public async Task When_ClaimsCheckerAttribute_return_false_Response_is_forbidden()
            {
                using (TestServer server = TestServer.Create(app => this.CreateConfiguration(app, false)))
                {
                    var response = await this.GetHttpResponseMessageAsync(server).ConfigureAwait(false);
                    Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
                }
            }

            [Fact]
            public async Task When_ClaimsCheckerAttribute_return_True_Response_is_Ok()
            {
                using (TestServer server = TestServer.Create(app => this.CreateConfiguration(app)))
                {
                    var response = await this.GetHttpResponseMessageAsync(server).ConfigureAwait(false);
                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
            }

            private async Task<HttpResponseMessage> GetHttpResponseMessageAsync(TestServer server)
            {
                var httpclient = new HttpClient(server.Handler);
                var uri = string.Format("{0}{1}", this._uri, "ADA34C15-82B7-4C05-90CB-B2EC4D43B481");

                HttpResponseMessage response = await httpclient.DeleteAsync(uri).ConfigureAwait(false);
                return response;
            }
        }
    }
}